package net.lab1024.sa.gateway.scheduler;

import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

import java.util.concurrent.Executors;

@Component
public class CustomScheduler {
    // 根据请求路径动态分配线程池（避免IO阻塞Netty线程）
    public Scheduler dispatch(ServerWebExchange exchange) {
        String path = exchange.getRequest().getURI().getPath();
        if (path.startsWith("/api/file")) {
            return Schedulers.fromExecutor(Executors.newFixedThreadPool(10)); // 文件上传专用
        } else {
            return Schedulers.fromExecutor(Executors.newFixedThreadPool(20)); // 通用业务
        }
    }
}